#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@his-pc>
#
# Distributed under terms of the MIT license.

"""

"""

class ListNode(object):

    def __init__(self, val, next=None):
        self.val = val
        self.next = next


import copy


class Solution:
    """
    hashTable 是[]
    hashTable中每个元素是ListNode
    """
    def rehashing(self, hashTable):
        # print(hashTable)
        # print(type(hashTable))
        # print(hashTable[2])
        # print(type(hashTable[2].val))
        new_capacity = len(hashTable) * 2

        dummy_node = ListNode('dummy')
        self.new_hash_table = [copy.copy(dummy_node) for i in range(new_capacity)]      # 深拷贝
        self.new_hash_table_tail = copy.copy(self.new_hash_table)                           # 浅拷贝

        for head in hashTable:
            node = head
            while node:
                save_node = node.next
                self.hash_node(node, new_capacity)
                node.next = None
                node = save_node

        for idx, node in enumerate(self.new_hash_table):
            self.new_hash_table[idx] = node.next

        return self.new_hash_table


    def hash_node(self, node, new_capacity):
        hash_idx = node.val % new_capacity
        self.new_hash_table_tail[hash_idx].next = node
        self.new_hash_table_tail[hash_idx] = node


def main():
    print("start main")
    node = ListNode(3)

    s = Solution()
    s.rehashing([None, node])

if __name__ == "__main__":
    main()
